package com.amigo.online.provider.compare.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Component;

import com.amigo.online.provider.common.entity.VideoMongoInfo;
import com.amigo.online.provider.common.entity.VideoMysqlInfo;
import com.amigo.online.provider.common.entity.VideoSolrInfo;

@Mapper
@Component
public interface VideoComparisonMapper {

    @Select(" select id from video_tbl order by id  desc limit 1")
    Integer getVideoMaxId();

    @Select("select id, nickname from video_tbl where id >= ${startId} and id <= #{endId} and deleted = 0 ")
    List<VideoMongoInfo> listfindByStartIdAndEndIdForMongo(@Param("startId") int startId, @Param("endId") int endId);

    @Select("select id, nickname from video_tbl where id >= ${startId} and id <= #{endId} and deleted = 0")
    List<VideoSolrInfo> listfindByStartIdAndEndIdForSolr(@Param("startId") int startId, @Param("endId") int endId);

    @Select("select id, nickname from video_tbl where id >= ${startId} and id <= #{endId} and deleted = 0")
    List<VideoMysqlInfo> listfindByStartIdAndEndId(@Param("startId") int startId, @Param("endId") int endId);

    @Select("SELECT t1.id FROM video_tbl t1"
            + " JOIN (SELECT ROUND(RAND() * ((SELECT MAX(id) FROM video_tbl)-(SELECT MIN(id) FROM video_tbl))+(SELECT MIN(id) FROM video_tbl)) AS id) AS t2"
            + " WHERE t1.id >= t2.id ORDER BY t1.id LIMIT #{number}")
    List<VideoMysqlInfo> listVideoInfoWithNumber(@Param("number") int randomComparsionNumber);
}
